#include <iostream>
#include <vector>
#define int long long 
using namespace std;

bool func(const vector<int>& A, int M, int K) {
    int sum = 0;
    int cnt = 0;
    for (int num : A) {
        sum += num;
        if (sum >= M) {
            cnt++;
            sum = 0;
            if (cnt >= K) {
                return true;
            }
        }
    }
    return cnt >= K;
}

signed main() {
    int N;
    int M;
    cin >> N >> M;
    vector<int> A(N);
    int total = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        total += A[i];
    }
    if (total < M) {
        cout << -1 << endl;
        return 0;
    }
    int K_max = total / M;
    int low = 1, high = K_max;
    int best = 0;
    while (low <= high) {
        int mid = (low + high) / 2;
        if (func(A, M, mid)) {
            best = mid;
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }
    if (best == 0) {
        cout << -1 << endl;
    } else {
        cout << N - best << endl;
    }
    return 0;
}
